package com.newx.limit.config;

import com.newx.limit.handler.interceptor.BrushInterceptor;
import com.newx.limit.manage.LimiterManager;
import com.newx.limit.manage.impl.GuavaLimiter;
import com.newx.limit.manage.impl.RedisLimiter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * @author yxl
 * @date 2024/7/5 0005 18:07
 */
@Configuration
public class NewxLimiterConfigure {

    @Bean
    @ConditionalOnProperty(name = "newx.limit.type",havingValue = "guava")
    public LimiterManager guavaLimiter(){
        return new GuavaLimiter();
    }


    @Bean
    @ConditionalOnProperty(name = "newx.limit.type",havingValue = "redis")
    public LimiterManager redisLimiter(StringRedisTemplate stringRedisTemplate){
        return new RedisLimiter(stringRedisTemplate);
    }

    @Bean
    @ConditionalOnProperty(name = "newx.limit.type",havingValue = "custom")
    public BrushInterceptor brushInterceptor(){
        return new BrushInterceptor();
    }
}
